package pinkblob.log;

import java.io.IOException;

import org.apache.log4j.FileAppender;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;

@SuppressWarnings("unchecked")
public class Log {

	private String LOGPINKBLOBFILE = System.getProperty("java.io.tmpdir")
			+ "PinkBlob.log";
	private String LOGPATH = System.getProperty("java.io.tmpdir");
	private String LOGPATTERN = "%d{ABSOLUTE} [%t] %5p - %c{1}:%L %x - %m%n";

	Logger log = null;
	Class clas = null;

	public Logger getLogger(Class clas) {
		this.clas = clas;
		log = Logger.getLogger(clas);
		try {
			String logfile = LOGPATH + clas + ".log";
			FileAppender app = new FileAppender(new PatternLayout(LOGPATTERN),
					logfile, true);
			FileAppender general_app = new FileAppender(new PatternLayout(
					LOGPATTERN), LOGPINKBLOBFILE, true);
			app.setName("FileApp");
			general_app.setName("GenApp");
			log.setLevel(Level.DEBUG);
			log.removeAllAppenders();
			log.addAppender(app);
			log.addAppender(general_app);
			log.info("Log for " + clas + " has been initialized (PATH: "
					+ logfile + ")");
		} catch (IOException ex) {
			log.info("couldn't configure this log4j instance properly...");
		}
		return log;
	}

}
